package com.bawei.module_home.discovery.adapter.provider

import android.widget.ImageView
import android.widget.TextView
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.library_common.arouter.ARouterActivityPath
import com.bawei.library_common.bean.VideoHeaderBean
import com.bawei.library_common.utils.DateTimeUtils
import com.bawei.library_common.utils.ImageUtils
import com.bawei.module_home.R
import com.bawei.module_home.discovery.entity.DiscoveryEntity
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * @Author : yaotianxue
 * @Time : On 2023/5/30 09:13
 * @Description : VideoCardProvider
 */
class VideoCardProvider(override val itemViewType: Int, override val layoutId: Int) :BaseItemProvider<DiscoveryEntity.Item>() {
    override fun convert(helper: BaseViewHolder, item: DiscoveryEntity.Item) {
        var imageView = helper.getView<ImageView>(R.id.iv_video_cover)
        ImageUtils.loadImageView(context,item.data.cover.detail,imageView)
        var tvTitle = helper.getView<TextView>(R.id.tv_video_title)
        tvTitle.text = item.data.title.toString()
        var textView = helper.getView<TextView>(R.id.textView)
        textView.text = item.data.author.name.toString()
        //时间 s--》00：00
        var tvTime = helper.getView<TextView>(R.id.tv_video_time)
        tvTime.text =  DateTimeUtils.format(item.data.duration).toString()

//        var videoTitle: String,
//        var category: String,
//        var video_description: String,
//        var collectionCount:Int,
//        var shareCount:Int,
//        var avatar: String,
//        var nickName: String,
//        var userDescription: String,
//        var playerUrl: String,
//        var blurredUrl: String,
//        var videoId:Int
        //为图片设置点击事件
        imageView.setOnClickListener {
           var videoHeaderBean =  VideoHeaderBean(
               item.data.title,
               item.data.category,
               item.data.description,
               item.data.consumption.collectionCount,
               item.data.consumption.shareCount,
               item.data.author.icon,
               item.data.author.name,
               item.data.author.description,
               item.data.playUrl,
               item.data.cover.blurred,
               item.data.id

           )

            ARouter.getInstance()
                .build(ARouterActivityPath.PAGER_PLAYER)
                .withParcelable("videoInfo",videoHeaderBean)//Parcelable读写内存，效率高
                .navigation()

        }

    }
}